package com.example.day3.exercise;

import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * 用stream打印九九乘法表
 */
public class Exercise7 {
    public static void main(String[] args) {
        IntStream.rangeClosed(1, 9)
                .forEach(i -> {
                    IntStream.rangeClosed(1, i)
                            .forEach(j -> System.out.print(j + "*" + i + "=" + (i * j) + "\t"));
                    // 每输出完一行后换行
                    System.out.println();
                });

        // 第二种实现方法
        /*IntStream.rangeClosed(1, 9)
                .boxed()
                .flatMap(x -> Stream.concat(
                        IntStream.rangeClosed(1, x)
                                .mapToObj(y -> y + "*" + x + "=" + y * x + "\t"),
                        Stream.of("\n")
                ))
                .forEach(System.out::print);*/
    }
}
